Customizing Values
In this section, we'll introduce the newVariable task and utilize the replace task to customize the API's URL so that we can receive a slightly different output.
Get Prepared to Pass Variables
With the test API we've been using, you can have some additional fun by injecting your own name within the Chuck Norris facts. Fortunately, the test API we've been using will allow us to demonstrate this, but first, we'll need to set-up some more tasks to handle the additional information.
There are a few ways to do this, but for purposes of this guide, we'll stick with a simple method that uses a few replace tasks and newVariable tasks to illustrate how variables are passed within an automation. As you become more comfortable with the capabilities of IAP and other various tasks, you may discover another more efficient method to accomplish the same goal.
Add More Tasks to an Automation
From the Task Menu Sidebar, add the following:
- Three (3)
newVariable
tasks - Two (2)
replace
tasks
Warning: At this point in your automation build, you'll discover that you need to rearrange the additional tasks on the canvas to ensure they are all clearly visible. Just click/hold and drag them to their desired location. Depending on the size of your monitor and how visually organized you are, the process of rearranging the various tasks on a canvas may (surprisingly) take some extra time.
Build the API URI
The Chuck Norris API will accept the following format and return a customized name within the fact.
http://api.icndb.com/jokes/random?firstName={firstname}&lastName={lastName}
- Click to open one of the newVariable tasks you just added.
- Provide
FactURL
as the New Variable Name. - Provide this value (without quotes):
http://api.icndb.com/jokes/random?firstName=customfirstname&lastName=customlastname
. - Save the task.
This newVariable
will be used as a template for the API URI we'll submit later on. If you were to submit it now "as is", it would be rather boring, so let's continue.
Build the Custom Name Variables
From the sample URI template above, you'll see that you can add a firstname
and lastname
to the API.
- Click to open one of the remaining newVariable tasks you added.
- Provide
MyFirstName
as the New Variable Name. - Provide the value (without quotes) of whatever
Firstname
would amuse you. - Save the task.
- Click to open the third and final newVariable task.
- Provide
MyLastName
as the New Variable Name. - Provide the value (without quotes) of whatever
Lastname
would amuse you. - Save the task.
Start Connecting Tasks
Next, you'll connect all the tasks:
- Delete the transition between START and the FetchFact task.
- Add a transition from START to the FactURL task.
- Add a transition from FactURL to the MyFirstName task.
- Add a transition from MyFirstName to the MyLastName task.
- Add a transition from MyLastName to one of the replace tasks you added earlier.
Configure the Replace Tasks
The replace tasks will help you swap out the generic customfirstname
and customlastname
phrases in the URL value of our FactURL
task with something more interesting.
Click to open the replace task you connected in the previous section.
Change the Summary to "FirstName-Update".
For the
str
variable:- Change the Reference task to
New Variable: FactURL
. - Keep the default
value
for the Reference variable.
- Change the Reference task to
For the
substr
variable:- Keep the Reference task setting as
static
. - Change the Reference variable to (without quotes)
customfirstname
.
You will probably recognize this value (phrase) from the URL that was provided for the FactURL task.
- Keep the Reference task setting as
For the
newSubstr
variable:- Change the Reference task to
New Variable: MyFirstName
. - Keep the default
value
for the Reference variable.
- Change the Reference task to
Save the task.
Add a transition from the "FirstName-Update" task to the other replace task you previously created.
Click to open the second replace task.
Change the Summary to "LastName-Update".
For the
str
variable:- Change the Reference task to
FirstName-Update
. - Keep the default
value
for the Reference variable.
- Change the Reference task to
For the
substr
variable:- Keep the Reference task setting as
static
. - Change the Reference variable to (without quotes)
customlastname
.
Again, you will probably recognize this value (phrase) from the URL that was provided for the FactURL task.
- Keep the Reference task setting as
For the
newSubstr
variable:- Change the Reference task to
New Variable: MyLastName
. - Keep the default
value
for the Reference variable.
- Change the Reference task to
Save the task.
As a checkpoint, let's review what you've done so far:
- Created a URL template ("FactURL").
- Created new (placeholder) variables for the First and Last name values (
MyFirstName
andMyLastName
, respectively). - Created two tasks that sequentially take the FactURL template and swap out firstName and lastName information into the appropriate spots within the URL.
Now all you need to do is provide the updated URL to the RestCall itself.
Finish Connecting & Configuring Tasks
Complete these last few steps to connect and configure all your tasks:
- Add a transition from the LastName-Update task to the FetchFact task.
- Click to open the FetchFact task.
- Change the
uri
variable:- Change the Reference task to
LastName-Update
. - Keep the default
replacedString
value for the Reference variable.
- Change the Reference task to
- Save the task.
You should now have an automation with nine (9) connected tasks in the following order:
START
FactURL
MyFirstName
MyLastName
FirstName-Update
LastName-Update
FetchFact
Query
(IsolateFact)END
Figure 1. Connected Tasks
Run the Automation
After running the automation, go to the IsolateFact (Query) Task History within Job Manager. You should find that instead of "Chuck Norris", the joke now uses your custom name.
Figure 2. Custom Name Value
Summary Wrap-Up
A job well done! You've learned how to create a URL template, customize values in your sample API, and build a more complex automation using the replace and newVariable tasks.
In the next section, you'll create a user input form that allows you to reuse the custom name automation you just built.